const { defineConfig } = require('@vue/cli-service')
const path = require('path')
const { exec } = require('child_process')
function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  publicPath: '/revenuemanage/',

  devServer: {
    open: false,
    setupMiddlewares(middlewares, devServer) {
      if (!devServer) {
        throw new Error('webpack-dev-server is not defined');
      }
      const port = devServer.options.port || 8080;
      const url = `http://localhost:${port}/revenuemanage/account`;
      exec(`start ${url}`);
      return middlewares;
    }
  },

  chainWebpack(config) {
    config.module
      .rule('svg')
      .exclude.add(resolve('src/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
  }
})
